package com.erp.myAdapter

import android.annotation.SuppressLint
import android.content.Context
import android.graphics.Color
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.LinearLayout
import android.widget.TextView
import com.erp.R
import com.erp.bean.YuliaoPrintBean
import com.erp.util.Myutil
import kotlinx.android.synthetic.main.lv_yuliao_item.view.*

class YuliaoPrintAdapter (var YuliaoPrintList: MutableList<YuliaoPrintBean>, var context: Context): BaseAdapter() {
    var minflater: LayoutInflater = LayoutInflater.from(context)
    @SuppressLint("InflateParams")
    override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
        var v : View
        var vh : ViewHolder
        if(convertView==null){
            v = minflater.inflate(R.layout.lv_yuliao_item,null)
            vh = ViewHolder(v)
            v.tag = vh
        }else{
            v = convertView
            vh = convertView.tag as ViewHolder
        }
        val bean=YuliaoPrintList[position]
        if(bean.kailiao_time != ""){
            vh.Llf.setBackgroundColor(Color.LTGRAY)
        }else{
            vh.Llf.setBackgroundColor(Color.WHITE)
        }
        Myutil.settv(bean.mcode,vh.tvCode)
        Myutil.settv(bean.m_size,vh.tvSize)
        Myutil.settv(bean.color_color,vh.tvColor)
        Myutil.settv(bean.mb_area_num,vh.tvQuhao)
        Myutil.settv(bean.m_name,vh.tvMingcheng)
        Myutil.settv(bean.m_counts,vh.tvCount)
        return v
    }

    override fun getItem(position: Int): Any = YuliaoPrintList[position]

    override fun getItemId(position: Int): Long = position.toLong()

    override fun getCount(): Int = YuliaoPrintList.size

    class ViewHolder(v: View) {
        var tvCode: TextView = v.tvCode
        var tvSize: TextView = v.tvSize
        var tvColor: TextView = v.tvColor
        var tvQuhao: TextView = v.tvQuhao
        var tvMingcheng: TextView = v.tvMingcheng
        var Llf: LinearLayout = v.Llf
        var tvCount : TextView = v.tvCount
    }
}